(function(angular) {
	'use strict';
	angular.module('fs.waf').controller('cda.facility.viewController', viewController);
	viewController.$inject = [ '$scope', '$q', 'Constants', 'gridService', 'modalService', 'layoutConfig', 'validatorConfig', 'authService','facilityService' ];
	function viewController($scope, $q, Constants, gridService, modalService, layoutConfig, validatorConfig, authService, facilityService) {
		var ctrl = this, log = $scope.loggerFactory.getLogger("cateView");
		var facilityInfo = $scope.$stateParams.params;
		ctrl.layoutConfig = layoutConfig;
		ctrl.validatorConfig = validatorConfig;
		
		ctrl.init = function() {			
			facilityService.initTree($scope, ctrl);
			ctrl.limitSelected = function (){
				return false;
			};
			ctrl.innerGridOptions = gridService.createInnerGridOptions($scope, ctrl.layoutConfig.formConfigs.attributes.tableConfigs.table, rowSelectionChanged);
			ctrl.innerGridOptions.data = 'vm.facility.facilityAttrList';
			ctrl.innerGridOptions.enableRowHeaderSelection = false;
			
			function rowSelectionChanged(eventRow, selectedRows) {
				ctrl.selectedDPParmList = selectedRows;
			}
			var params = {
					facilityId : facilityInfo.id || facilityInfo.facilityId
				};			
			
			return authService.view(params).then(function(response) {
				ctrl.facility = response.data || facility;
			}, angular.noop);
		};
	
	}
})(angular);